package com.fg.exemplocrudengenhariadesoftware.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class FileUtil {

	public static InputStream getInputStream(String fileName) {
        InputStream is = null;

    	try{
	        File file = new File(fileName);        
	        is = file.getClass().getResourceAsStream(fileName);
    	}catch (Exception e) {
		}

        if (is == null){
	        try {
	        	is = new FileInputStream(fileName);
	        } catch (Exception ex) {
	        }
        }

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        
        if (is == null){
        	try {
                is = ClassLoader.getSystemResourceAsStream(fileName);
            } catch (Exception e) {
            }
        }

        if (is == null) {
            try {
                is = classLoader.getResourceAsStream(fileName);
            } catch (Exception e) {
            }
        }

        if (is == null) {
            try {
                is = classLoader.getResourceAsStream("/" + fileName);
            } catch (Exception e) {
            }
        }

        if (is == null) {
            try {
                is = classLoader.getResourceAsStream("META-INF/" + fileName);
            } catch (Exception e) {
            }
        }

        if (is == null) {
            try {
                is = classLoader.getResourceAsStream("/META-INF/" + fileName);
            } catch (Exception e) {
            }
        }

        if (is == null) {
            try {
                is = classLoader.getResourceAsStream("WEB-INF/classes/" + fileName);
            } catch (Exception e) {
            }
        }

        if (is == null) {
            try {
                is = classLoader.getResourceAsStream("/WEB-INF/classes/" + fileName);
            } catch (Exception e) {
            }
        }
        
        return is;
    }
	
}
